package com.training.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.base.BaseAdapter;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.training.R;
import com.training.bean.CourseStage;
import com.training.utils.DensityUtils;

public class HomeAdapter extends BaseAdapter<CourseStage, HomeAdapter.ViewHolder> {
    public HomeAdapter(Context context, OnItemClickListener<CourseStage> listener) {
        super(context, listener);
    }

    @Override
    protected void onBindView(ViewHolder holder, int position, CourseStage courseStage) {
        holder.title.setText(courseStage.title);
        holder.synopsis.setText(courseStage.synopsis);
        // 加载圆角图片
        Glide.with(mContext)
                .load(courseStage.cover)
                .transform(new RoundedCorners(DensityUtils.dp2px(mContext,26)))  //  圆角
                .into(holder.cover);

    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_course_stage, parent, false));
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public ImageView cover;
        public TextView title;
        public TextView synopsis;
        public TextView study;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            cover = itemView.findViewById(R.id.cover);
            title = itemView.findViewById(R.id.title);
            synopsis = itemView.findViewById(R.id.synopsis);
            study = itemView.findViewById(R.id.study);
        }
    }
}
